package com.baizhi.obj1;

public class StudentDemo {
    public static void main(String[] args) {
        Student st = new Student();
       // st.name = "安尚华";
        //st.age = -30;
        st.setName("安尚华");
        st.setAge(30);

        System.out.println(st.getAge());

        //Student st2 = new Student("001","Bob",-20,'男',"英国伦敦");
       // System.out.println(st2.age);
    }
}

/**
 * 学生类
 */
class Student{
    //类的封装，就是所有的属性都私有化， 提供getXXX方法和setXXX方法
    private String stuId;
    private String name;
    private int age;
    private char gender;
    private String address;

    public void setName(String name){
        this.name = name;
    }

    public String getName(){
        return name;
    }

    public void setStuId(String stuId){
        this.stuId = stuId;
    }

    public String getStuId(){
        return stuId;
    }


    //提供一个对外修改age的方法，让用户可以给age赋值
    public void setAge(int age){
        if(age<0){
            System.out.println("您输入的年龄值不合法");
            return;
        }
        this.age = age;
    }

    //提供一个对外访问age的方法，让用户可以访问age
    public int getAge(){
        return age;
    }










    //无参构造
    public Student(){

    }

    //含参构造
    public Student(String stuId,String name,int age,char gender,String address){
        this.stuId = stuId;
        this.name = name;
        if(age<0){
            System.out.println("年龄不合法");
            return;
        }
        this.age = age;
        this.gender = gender;
        this.address = address;
    }




    public void study(){
        System.out.println("学习");
    }


}
